package com.geostar.mina.decoder;


import java.nio.charset.Charset;  
import java.nio.charset.CharsetDecoder;  
import org.apache.mina.core.buffer.IoBuffer;  
import org.apache.mina.core.session.IoSession;  
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;  
import org.apache.mina.filter.codec.ProtocolDecoderOutput;  

import com.geostar.mina.model.ProcessModel;
  
/**
 * 文件名:HDecoder.java
 * 功能: 自定义解码器
 * 目前支持方法
 * --------------------------------------
 * 初始版本 
 * 作者: yesong
 * 时间: Apr 14, 2014
 */
public class HDecoder extends CumulativeProtocolDecoder {  
    private final Charset charset;  
  
    public HDecoder(Charset charset) {  
        this.charset = charset;  
    }  
  
    @Override  
    protected boolean doDecode(IoSession arg0, IoBuffer message,  
            ProtocolDecoderOutput arg2) throws Exception {  
        CharsetDecoder cd = charset.newDecoder();  
        
        String id = message.getString(cd);
        
        ProcessModel pm = new ProcessModel();
        
          
        arg2.write(pm);  
        return true;  
    }  
}  
